<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>margin塌陷</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            border: 1px solid #ccc;
        }

        .parent {
            width: 100px;
            height: 100px;
            background: #000;
            margin-top: 50px;
            margin-left: 50px;
        }

        .sub {
            margin-left: 20px;
            margin-top: 40px;
            width: 50px;
            height: 50px;
            background: orange;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="parent">
            <div class="sub"></div>
        </div>
    </div>
</body>
</html>